package com.headfirst.observer.version1;

/**
 * @author sunhongguang
 * @create 2022-01-18-1:20
 */
public class ForecastDisplay implements Observer,DisplayElement {
    private float currentPressure = 29.92f;
    private float lastPressure;
    private Subject weatherData;

    public ForecastDisplay(Subject weatherData){
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }

    @Override
    public void display() {
        System.out.print("Forecast: ");
        if(currentPressure > lastPressure){
            System.out.println("Improving weather on the way!");
        }else if(currentPressure == lastPressure){
            System.out.println("More of the same");
        }else if(currentPressure < lastPressure){
            System.out.println("Watch out for cooler,rainy weather");
        }
    }

    @Override
    public void update(float temperature, float humidity, float pressure) {
        lastPressure = currentPressure;
        currentPressure = pressure;
        display();
    }
}
